#ifndef SCRIPT_THREAD_H
#define SCRIPT_THREAD_H

#include <QObject>
#include <QThread>
#include <QJSEngine>
#include <QSemaphore>
#include <QList>
#include <QMediaPlayer>
#include <QMutex>
#include "command.h"

class Script_thread : public QThread
{
    Q_OBJECT
public:
    explicit Script_thread(Command *cmd = 0, QObject *parent = 0);

	int		test;
	QString tstr;


	void quit();

	int create_console_object(QString name,QObject *console);


private:
	Command *command;
	QJSEngine js;
	QSemaphore *con_sem;
	QSemaphore *js_sem;
	QSemaphore *play_sem;
	QStringList js_code;
	QMediaPlayer *player;
	char		play_state;
	bool quit_flag;
	void *rule;
	QString rule_result;
	QMutex	mutex;
	


protected:
	void run();

signals:

public slots:
	void print(QString str);

	int get_play_state();

	int play(QString,int ms);
	int play(QString);
	int run_js(QString);
	bool get_quit();
	bool sleep(int ms);

private slots:
	int run_js_code(QString code);
	void positionChanged(qint64);
	void handleError(QMediaPlayer::Error);
	void play_state_changed(QMediaPlayer::State state);
	
};

#endif // SCRIPT_THREAD_H
